package com.eqdd.yiqidian.ui.act.tree

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.widget.RecyclerView
import android.view.View
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.bean.TypeTreeBean
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.JsonCallBack
import com.eqdd.yiqidian.kotlin.toArrayList
import com.jhj.datalibrary.interfaces.OnCustomTopbarListener
import com.jhj.datalibrary.tree.single.BaseSingleListAdapter
import com.jhj.datalibrary.tree.single.BaseSingleTreeActivity
import com.jhj.datalibrary.tree.single.BaseSingleTreeAdapter
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.layout_title.view.*
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by jhj on 18-9-29.
 */
class ActTypeTreeActivity : BaseSingleTreeActivity<TypeTreeBean>() {

    override val adapter: BaseSingleTreeAdapter<TypeTreeBean, out RecyclerView.ViewHolder>
        get() = ActTypeTreeAdapter(this)
    override val mAdapter: BaseSingleListAdapter<TypeTreeBean, out RecyclerView.ViewHolder>
        get() = ActTypeListAdapter(this)


    @SuppressLint("MissingSuperCall")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initTopBar(R.layout.layout_title, object : OnCustomTopbarListener {
            override fun onLayout(view: View) {
                view.topBar_title.text = "活动分类"
                view.topBar_back.onClick {
                    finish()
                }
            }
        })


        OkGo.post<List<TypeTreeBean>>(HttpConfig.BASE_URL + HttpConfig.AREA_OPTIONS)
                .params("type", 50)
                .execute(object : JsonCallBack<List<TypeTreeBean>>() {
                    override fun onSuccess(response: Response<List<TypeTreeBean>>?) {
                        val httpResult = response?.body()
                        httpResult?.toArrayList()?.let {
                            initDataList(it)
                        }
                    }
                })
    }


}